home *** CD-ROM | disk | FTP | other *** search
/ The Business Master (3rd Edition) / The Business Master (3rd Edition).iso / files / texttors / nyedit21 / macros.arc / COMPRESS < prev    next >
Encoding:
Text File  |  1988-06-02  |  2.7 KB  |  90 lines

  1. /*****************************************************************************/
  2. /* COMPRESS -  implements a simple compressed viewer for source files        */
  3. /*   When you press the COMPRESS command (ALT-C is this implementation),     */
  4. /* all source lines which have some non-blank characters in the first        */
  5. /* 'CompressLevel' characters of the line are displayed. The obly legal      */
  6. /* keys in compressed viewing mode are UP, DOWN, PGUP, PGDN, ESC (exits      */
  7. /* compressed mode), + (increases the CompressLevel) and - (decreases the    */
  8. /* CompressLevel).                                                           */
  9. /*                                                                           */
  10. /* Written by Marc Adler  Magma Systems   1/5/88                             */
  11. /*                                                                           */
  12. /*****************************************************************************/
  13.  
  14. #include mekeys.h
  15.  
  16. #define TAB_LEVEL 2     /* Put your indentation level here */
  17.  
  18. int CompressLevel;
  19.  
  20. init()
  21. {
  22.   CompressLevel = TAB_LEVEL;
  23.   assign_key("compress", ALT_C);
  24. }
  25.  
  26. compress()
  27. {
  28.   old_buf = currbuf();
  29.   save_position();
  30.  
  31.   /* Create a new buffer which will hold the compressed view */
  32. start:
  33.   new_buf = create_buffer("THE COMPRESSED FILE");
  34.   gobof();
  35.   show_buffer(new_buf);
  36.   explode_window();
  37.   setcurrbuf(old_buf);
  38.  
  39.   /* Go thru the lines of the old buffer and pick all lines whose 1st */
  40.   /* non-blank character starts at a column less than CompressLevel.  */
  41.   while (1)
  42.   {
  43.     cl = currline();
  44.     if (ltrim(substr(cl, 1, CompressLevel)) != "")
  45.     {
  46.       /* Transfer the line to the new buffer */
  47.       setcurrbuf(new_buf);
  48.       insert(cl);  insert("\n");
  49.       gobol();
  50.     }
  51.     setcurrbuf(old_buf);
  52.     if (!down())  break;
  53.   }
  54.   
  55.   /* Display the compressed file listing */
  56.   setcurrbuf(new_buf);
  57.   gobof();
  58.   refresh();
  59.  
  60.   message(
  61. "Use UP,DOWN,PGUP,PGDN to move, + to increase level, - to decrease, ESC exits");
  62.  
  63.   while ((c = get_tty_char()) != CTRL_D && c != ESC)
  64.   {
  65.     if (c == _UP || c == _DOWN || c == PGUP || c == PGDN)       /* navigate */
  66.       command(c);
  67.     else if (c == '+')          /* increase compress level */
  68.     {
  69.       CompressLevel += TAB_LEVEL;
  70.       delete_buffer(new_buf);
  71.       setcurrbuf(old_buf);
  72.       goto start;
  73.     }
  74.     else if (c == '-' && CompressLevel > TAB_LEVEL)             /* decrease */
  75.     {
  76.       CompressLevel -= TAB_LEVEL;
  77.       delete_buffer(new_buf);
  78.       setcurrbuf(old_buf);
  79.       goto start;
  80.     }
  81.   }
  82.  
  83.   /* Get rid of the compress buffer and go back to the original buffer */
  84.   unexplode_window();
  85.   delete_buffer(new_buf);
  86.   setcurrbuf(old_buf);
  87.   restore_position();
  88. }
  89.  
  90.